/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.chl.da.ejb.persistency;

import edu.chl.da.ejb.core.Customer;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.criteria.CriteriaQuery;

/**
 *
 * @author Jakob
 */
@Stateless
public class CustomerFacade implements ICustomerFacade {
    @PersistenceContext(unitName = "airline_pu")
    private EntityManager em;

    @Override
    public void create(Customer customer) {
        em.persist(customer);
    }

    @Override
    public void edit(Customer customer) {
        em.merge(customer);
    }

    @Override
    public void remove(Customer customer) {
        em.remove(em.merge(customer));
    }

    @Override
    public Customer find(Object id) {
        return em.find(Customer.class, id);
    }

    @Override
    public List<Customer> findAll() {
        CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
        cq.select(cq.from(Customer.class));
        return em.createQuery(cq).getResultList();
    }

}
